package com.asa.control_theory;


public class A2  {

	/**
	 * 高阶微分方程转化为矩阵
	 * 我感觉它不只是控制论里有用，它实际上是高阶微分方程的一个推广，但解线性偏微分方程的时候没有说明
	 */
	/**************************y`` + a1*y` + a2*y = u 这种形式的*************************************/
	
	// x` = result*x + asa_u*u
	public static double[][] asa_x(double[] a) {
		// y`` + a1*y` + a2*y = u
		//这种形式的
		
		double[][] result = new double[a.length][a.length];
		
		
		for (int i = 0; i < result.length-1; i++) {
			result[i][i+1] = 1;
		}
		
		for (int i = 0; i < result.length; i++) {
			result[result.length-1][i] = -a[a.length-i-1];	
		}
		
		return result;
	}
	
	// x` = asa_x*x + result*u
	public static double[] asa_u(double[] a) {
		
		double[] result = new double[a.length];

		result[result.length-1] = 1;
		
		return result;

	}

	//y = result * x
	public static double[] asa_y(double[] a) {
		double[] result = new double[a.length];
		result[0] = 1;
		return result;

	}
	
	
	/**************************y`` + a1*y` + a2*y = b1*u``+ b2*u` + b3*u 这种形式的*************************************/

	
	//y = result * x
	public static double[] asb_y(double[] a,double[] b) {
		double[] result = new double[a.length];
		for (int i = 0; i < result.length; i++) {
			result[i] = b[b.length-i-1];	
		}
		return result;

	}
	
	
	//y = result * x + asc_u*u
	public static double[] asc_y(double[] a,double[] b) {
		double[] result = new double[a.length];
		for (int i = 0; i < result.length; i++) {
			result[i] = b[b.length-i-1] - a[a.length-i-1]*b[0];	
		}
		return result;

	}
	
	//y = asc_y * x + result*u
	public static double asc_u(double[] b) {
		return b[0];
	}
	
	
	
	
	
	
	public static void main(String[] args) {
		
		double[] a = {6,11,6};
		double[] b = {8,17,8};
		
		
		double[][] asa_x = asa_x(a);
		for (int i = 0; i < asa_x.length; i++) {
			for (int j = 0; j < asa_x[i].length; j++) {
				System.out.print( asa_x[i][j]+"    ");
			}
			System.out.println();
		}
		double[] asb_y = asb_y(a, b);
		
		for (int i = 0; i < asb_y.length; i++) {
			System.out.println(asb_y[i]);
		}
		
		
	}
	
	
	
	
	
	
	
	
}
